home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / lu62 / sendhs.c < prev    next >
C/C++ Source or Header  |  1996-07-10  |  10KB  |  290 lines

  1.  /**********************************************************
  2.  *                                                         *
  3.  *                      SENDHS                             *
  4.  *                SEND record to HS                        *
  5.  * This procedure requesting the HS for send processing    *
  6.  * with appropriate parms.                                 *
  7.  * The applicable parms are :                              *
  8.  *                  - FMH;                                 *
  9.  *                  - Send_data;                           *
  10.  *                  - Confirm;                             *
  11.  *                  - Confirmed;                           *
  12.  *                  - Flash;                               *
  13.  *                  - PREP_TO_RCV_FLUSH;                   *
  14.  *                  - PREP_TO_RCV_CONFIRM_SH;              *
  15.  *                  - PREP_TO_RCV_CONFIRM_LG;              *
  16.  *                  - Req_to_send;                         *
  17.  *                  - Deallocate_confirm;                  *
  18.  *                  - Deallocate_flush;                    *
  19.  *                  - Deallocate_abend;                    *
  20.  *                                                         *
  21.  * INPUT : type ( which describes the selected parm),      *
  22.  *         pointer to RCB.                                 *
  23.  *                                                         *
  24.  * OUTPUT: - 0 - OK;                                       *
  25.  *         - 1 - invalid request;                          *
  26.  *         - 2 - return code in RPL.                       *
  27.  *                                                         *
  28.  *                                                         *
  29.  * CopyRight 1995. Nicholas Poljakov all rights reserved.  *
  30.  *                                                         *
  31.  **********************************************************/
  32. #include <stdio.h>
  33. #include <malloc.h>
  34. #include <rcb.h>
  35. #include <scb.h>
  36. #include <prefix.h>
  37. #include <include.h>
  38. #include <string.h>
  39. #include <state1.h>
  40.  
  41. #define PRF_SIZ 31
  42.  
  43. #if OS_TYPE == 0 /* MS-DOS */
  44. int sk_r_wt(void *);
  45. int SendBlock(void *, void *);
  46. int setrc(void *, void *);
  47. int sendhsf(void *);
  48. int sendbm(void *, void *);
  49. int sendat(void *);
  50. int rtsend(void *);
  51. unsigned long rmfmh5(void *, void *);
  52. int recwait(void *);
  53. int rcvru(void *, void *);
  54. int rcvhs(void *, void *, void *, void *);
  55. int ralloc(void *, void *);
  56. int psrm(int, void *, void *);
  57. int ps_conv(int, void *);
  58. int proterr(void *, unsigned long);
  59. int preptrcv(void *, void *);
  60. int post_rcb(void *);
  61. struct repass *postopen(void *);
  62. int phsrec(void *);
  63. int pfmh5(void *);
  64. int opndst(void *);
  65. int obtsess(void *, unsigned char);
  66. int Lrf_handler(void *);
  67. int get_sess(void *, void *);
  68. int get_attr(void *);
  69. int fsm_error(unsigned char, void *);
  70. int fsm_conv(unsigned char, unsigned char, void *);
  71. int flush (void *);
  72. int dcp(void *);
  73. int dealloc(void *);
  74. int crtp(void *);
  75. int conv(void *);
  76. int chkparm(void *, void *);
  77. int check_end(unsigned int, void *);
  78. struct rqb *call_appl(void *);
  79. int buffmng(unsigned char, void *, void *, void *, unsigned, unsigned char, unsigned);
  80. unsigned long attltck(void *);
  81. unsigned long attacheck(void *);
  82. char *cgetmem(int, int);
  83. int sendhsf(void *);
  84. int opndst(void *);
  85. int alloc_rcb(void *, void *);
  86. int allocate(void *);
  87. int clsdst(void *);
  88. #endif
  89. int short sem_no;
  90.  
  91. sendhs(p_rcb)
  92. struct rcb *p_rcb;
  93. {
  94.         struct scb *p_scb;
  95.         struct prefix *p_prf;
  96.         struct prefix *t_prf;
  97.         struct prefix *tt_prf;
  98.         struct segprf *p_sp;
  99.         struct segprf *t_sp;
  100.         struct rqb *p_rqb;
  101.         char p1;
  102.         char *p;
  103.         unsigned int cnt;
  104.         unsigned int cnt1;
  105.         char *buff;
  106.         int rc;
  107.         unsigned char type;
  108.         int i;
  109.         unsigned char dsc;
  110.  
  111. #if OS_TYPE == 1
  112. /*********  Trace facility **********/
  113. unsigned int rtype;   /* type of record */
  114. unsigned int pnum;    /* point number */
  115. char pname[8];        /* name of module */
  116. char *drec;           /* record for dump */
  117. int  lenr;            /* record length */
  118.  
  119. rtype = INPROC;
  120. strcpy(pname, "sendhs");
  121. pnum = 1;
  122. drec = p_rcb;
  123. lenr = sizeof(struct rcb);
  124. gtf(rtype, pname, pnum, drec, lenr);
  125. /***********************************/
  126. #endif
  127.  
  128.         rc = 0;
  129.         cnt1 = 0;
  130.  
  131.         if (p_rcb -> p_scb == NULL) {
  132.              rc = 2;
  133.              goto sd_exit;
  134.         }
  135.         p_scb = p_rcb -> p_scb;
  136.         p_prf = p_rcb -> first_out;
  137.         if (p_prf == NULL) {
  138.                 rc = 1;
  139.                 goto sd_exit;
  140.         }
  141.         type = p_prf -> type;
  142.         cnt = p_prf -> lt_text;
  143.         if (cnt == 0) {
  144. #if OS_TYPE == 0 /* MS-DOS */
  145.             if ((p_rqb = cgetmem(1,16)) == NULL) {
  146. #endif
  147. #if OS_TYPE == 1 /* Unix V */
  148.             if ((p_rqb = calloc(1,16)) == NULL) {
  149. #endif
  150.                 rc = 1;
  151.                 goto sd_exit;
  152.             }
  153.             p_rqb -> th.ra.code = 0x80; /* RQB */
  154.             tt_prf = p_prf -> prev;
  155.             t_prf = p_prf;
  156.             p_prf = p_prf -> next;
  157.           /* Delete element from the output chain */
  158.             if (p_prf != NULL) {
  159.               p_prf -> prev = t_prf -> prev;
  160.             }
  161.             else
  162.                   {
  163.                       p_rcb -> first_out = NULL;
  164.                   }
  165.             if (tt_prf != NULL) {
  166.                 tt_prf -> next = p_prf;
  167.             }
  168.             free(t_prf);
  169.         }
  170.         else
  171.                 {
  172.                       i = 0;
  173.                       cnt1 = 0;
  174.                       t_sp = NULL;
  175.  
  176.                       do {
  177.                           dsc = p_prf -> dsc;
  178. #if OS_TYPE == 0 /* MS-DOS */
  179.                           if ((p_sp = cgetmem(1,(cnt + PRF_SIZ))) == NULL) {
  180. #endif
  181. #if OS_TYPE == 1 /* Unix V */
  182.                           if ((p_sp = calloc(1,(cnt + PRF_SIZ))) == NULL) {
  183. #endif
  184.                               rc = 1;
  185.                               goto sd_exit;
  186.                           }
  187.                           p = p_sp;
  188.                           p_sp -> len = cnt + 3; /* the segment length (i.e. RU + RH)*/
  189.                           if (i == 0) {
  190.                               p_rqb = p + 12;
  191.                               p_rqb -> th.ra.code = p_rqb -> th.ra.code & 0x7f; /*SEG*/
  192.                           }
  193.                           p += PRF_SIZ;
  194.                           memcpy(p, p_prf -> text, cnt);
  195.                           if (p_prf -> dsc == 0) {
  196.                               if (p_sp != NULL) {
  197.                                   p_sp -> link = NULL;
  198.                               }
  199.                           }
  200.                           if (t_sp != NULL) {
  201.                               t_sp -> link = p_sp;
  202.                           }
  203.                           i ++;
  204.                           cnt1 += cnt;
  205.                           t_sp = p_sp;
  206.                           tt_prf = p_prf -> prev;
  207.                           t_prf = p_prf;
  208.                           p_prf = p_prf -> next;
  209.                         /* Delete the element from an output chain */
  210.                           free(t_prf -> text);
  211.                           if (p_prf != NULL) {
  212.                             p_prf -> prev = t_prf -> prev;
  213.                             cnt = p_prf -> lt_text;
  214.                           }
  215.                           else
  216.                                 {
  217.                                     p_rcb -> first_out = NULL;
  218.                                 }
  219.                           if (tt_prf != NULL) {
  220.                               tt_prf -> next = p_prf;
  221.                           }
  222.                           free(t_prf);
  223.                       } while ((dsc != 0) && (p_prf -> lt_text != 0) && (p_prf != NULL));
  224.                 }
  225.  
  226.       /* Set the RQB fields and then call Pattach */
  227.  
  228.         p_rqb -> th.ra.rparm.parm.parm2 = type;
  229.         p_rqb -> th.ra.wa.hh.hscb = p_rcb -> sess_corl;
  230.         p_rqb -> th.ra.wa.rqba.rclass = cnt1;
  231.         p_rqb -> th.ra.stcb = APPL_CODE;
  232.         p_rqb -> th.ra.code = p_rqb -> th.ra.code & 0xbf; /* TOP */
  233.         p_rqb -> th.ra.wa.rqba.rsrlen = sem_no;
  234.         p_rqb -> th.ra.rparm.parm.parm1 = 1; /* Send */
  235.  
  236. #if OS_TYPE == 1
  237. /***********************************/
  238. rtype = GREC;
  239. strcpy(pname, "sendhs");
  240. pnum = 2;
  241. if (p_rqb -> th.ra.code & 0x80) {
  242.    drec = p_rqb;
  243.    lenr = 16;
  244.    gtf(rtype, pname, pnum, drec, lenr);
  245. }
  246. else {
  247.        drec = p_sp;
  248.        lenr = 31;
  249.        gtf(rtype, pname, pnum, drec, lenr);
  250.      }
  251. /***********************************/
  252.         pattach(p_rqb);
  253. #else
  254.         call_appl(p_rqb);
  255. #endif
  256. #if OS_TYPE == 1 /* Unix V */
  257.         p1 = p_rqb -> th.ra.code & 0x80;
  258.         if (p1 == 0x80) { /* RQB */
  259.             free(p_rqb);
  260.         }
  261.         else
  262.                 {
  263.                     free(p_sp);
  264.                 }
  265. #endif
  266.  
  267. sd_exit:
  268.          switch (rc) {
  269.             case 0 :
  270.                       {
  271.                           p1 = RESET;
  272.                           fsm_error(p1, p_rcb);
  273.                           break;
  274.                       }
  275.             case 1 :
  276.                       {
  277.                           p1 = ALLOC_FAIL_RETRY;
  278.                           fsm_error(p1, p_rcb);
  279.                           break;
  280.                       }
  281.             case 2 :
  282.                       {
  283.                           p1 = ALLOC_FAIL_NO_RETRY;
  284.                           fsm_error(p1, p_rcb);
  285.                           break;
  286.                       }
  287.           }
  288.          return (rc);
  289. }
  290.